package com.eshop.we.result;

import com.eshop.we.constants.BaseConstants;

import java.io.Serializable;

/**
 * @author wangzhanguo
 * @create 2018-07-09 14:52
 **/

public class Result <T> implements Serializable{
    private Integer code;

    private String msg;

    private T data;

    public Result(Integer code,String msg,T t){
        this.code = code;
        this.msg = msg;
        this.data = t;
    }

    public static <E> Result success(){
        Result result = new Result<E>(BaseConstants.SUCCESS_CODE,null,null);
        return result;
    }

    public static <E> Result success(E e){
        Result result = new Result<E>(BaseConstants.SUCCESS_CODE,null,e);
        return result;
    }

    public static <E> Result success(String msg,E e){
        Result result = new Result<E>(BaseConstants.SUCCESS_CODE,msg,e);
        return result;
    }

    public static <E> Result fail(){
        Result result = new Result<E>(BaseConstants.FAIL_CODE,null,null);
        return result;
    }

    public static <E> Result fail(E e){
        Result result = new Result<E>(BaseConstants.FAIL_CODE,null,e);
        return result;
    }

    public static <E> Result fail(String msg,E e){
        Result result = new Result<E>(BaseConstants.FAIL_CODE,msg,e);
        return result;
    }

    public static <E> Result rtn(Integer code,String msg,E e){
        Result result = new Result<E>(code,msg,e);
        return result;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
